home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: Passing Function Pointers
- Date: 31 Mar 1996 22:24:03 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4jn0m3$1ae@sparcserver.lrz-muenchen.de>
- References: <315E7284.479F@sooner.net>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- Eddie Bush <edwbush@sooner.net> writes:
-
- [He wants to pass a callback function to a delete function for nodes
- in a list]
-
- >I have used this technique under UN*X platforms using gcc to compile, and
- >it works just fine. It has been a while since I've done it though, so I
- >am thinking that maybe it is not just perfectly correct or something.
- >Anyhow, here it is:
-
- >void delete (list *my_list, int *fn){
- >
- > l_node temp_node = (*my_list) -> head;
- >
- > if (!is_empty(*my_list)){
- > (*my_list) -> head = (*my_list) -> head -> next;
- > (*my_list) -> head -> pre = NULL;
- > }
- > (*fn) (temp_node);
-
- fn is a pointer to int. *fn is an int, i.e. _not_ a function so
- if your compiler tells you that you are calling a non-function,
- why don't you trust it?
-
- > free (temp_node);
- >}
-
- >I made *fn an int because it didn't like the void, and now instead of
- >complaining about that it complains about - well, here's the error
- >message:
-
- >Error LIST.H 71: Call to nonfunction.
-
- >Any ideas? It isn't 'clicking' for me. Is this something to do with the
- >version (Borland C/C++ 3.0) I am running maybe? I passed pointers to
- >functions fine using the gcc compiler!
-
- Well, all versions of gcc available to me do not allow calling an
- int as a function. Are you abolutely sure that your functions
- signature did not look suspiciously similar to
-
- void delete (list *my_list, int (*fn)(l_node));
-
- Hint: If you make claims about a certain compiler, be sure it is
- Frolic C, available on the Frozzietec CD 6400 only. Otherwise, there
- might be someone reading your article who has access to that compiler.
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
-